The present invention relates to methods improving and enhancing the operation of Java programs on various hardware platforms. More specifically, the present invention relates to method for employing a new set of platform-specific Java classes to both reduce the size of the resulting Java executable code and to provide a performance improvement when the Java executable code is run. A software product is also disclosed.
Developers of programs which are platform aware due to their compilation and execution model, such as those developed in the C and C++ programming languages, can take advantage of language preprocessors. The preprocessor for a language like C also permits a developer to define (e.g. via the #define directive) and use fixed constants. Such constants are frequently platform specific in nature. Language preprocessors also allow for the inclusion of conditional directives (e.g. #ifdef or #if), which in turn are used to select specific variants of code to be included or excluded during the subsequent compilation process, which in turn has an effect on the executable file produced by the compiler. The use of such constants and directives allows developers and language compiler software to better tune the output of the program compilation process in order to it generate and execute more space and performance efficient machine-specific code. This is particularly of interest when developing software for embedded devices such as those which exist in the new category of information appliances.
Java is a totally object-oriented, platform independent programming language, which achieves architectural independence by compiling source code into its own intermediate representation. Java source code is not compiled into normal machine code, but is translated into code, i.e., bytecode, for a virtual machine specifically designed to support Java""s features. A Java interpreter or a Java-enabled browser then executes the translated code. While Java source code must be compiled, no link step is required since the Java interpreter dynamically links the translated code at run time. Java programs are usually classified as either applications, which are run on a Java interpreter, or applets, which are run by a Java-enabled browser. See U.S. Pat. No. 5,933,144, which patent is incorporated herein by reference for all purposes.
Java Beans is a component model for building and using Java-based software components. A xe2x80x9cbeanxe2x80x9d is simply a Java class with extra descriptive information, similar to the concept of an object linking and embedding (OLE) type library. Unlike an OLE library, however, a bean is usually self-describing, including a file which contains the class""s symbol information and method signatures and which may be scanned by a development tool to gather information about the bean. Any Java class with public methods may be considered a bean, but a bean typically has properties and events as well as methods.
Java is well-suited for implementation in graphical user environments or object-oriented interfaces. The Java abstract window toolkit (AWT) allows graphical user interface (GUI) objects to be treated in a generic manner without regard to the system on which the program is running. Combined with the feature of platform-independence, this feature promotes faster development of Internet and cross-platform software using Java.
Thus, Java, being a highly portable platform independent programming language, does not provide the preprocessing capability available for other languages. Stated another way, Java does not possess an innate ability or capability for being optimized with respect to a specific platform, despite the obvious needs for smaller code sizes and better platform-specific performance. While Java Beans are designed to be adaptable, these beans provide adaptability only at the cost of efficiency in terms of execution time and memory usage. These costs compound the already notable efficiency cost of Java""s portability. Moreover, since Java is fast becoming a dominant language in the development of programming for a variety of information appliances and small computing devices such as Java Network Computers, the inability to customize certain programming for the devices in question is a significant drawback in terms of program size and efficiency.
It will be appreciated that the preprocessor technique common to C and C++ languages does not work for Java because Java software is distributed in the compiled class-file format. As such, there needs to be another method used to achieve the efficiency gains of what a preprocessor achieves in C and C++, but compatible with the portable, compiled class-file architecture of Java.
It will also be appreciated that Java run-time optimization tools, such as Just In Time (JIT) compilers, do exist. However, there are no tools which allow for selective code inclusion/exclusion optimizations to occur as a selective process during the initial or on-going use of a Java program. For example, while IBM""s international patent WO98/37486 discloses the loading of Java class files on demand, that is more an issue of a Java-specific memory paging technique than one which deals with platform specific optimizations and execution. Moreover, Sun Microsystems""s European patent application EP 0913 769 A2 details a method to preprocess and package class files in order to remove duplicate data for better memory usage. However, the EP ""769 application does not operate in a fashion remotely similar to that of a language preprocessor, which includes the ability to process conditional control flow directives. Both of the above-mentioned documents are incorporated herein by reference for all purposes.
What is needed is a method for optimizing Java applications in a platform specific manner. Moreover, what is needed is a method for optimizing Java applications in which the platform specific advantages of a tool like a C preprocessor are available. It would be beneficial if the method would employ both constants and conditional logic in optimizing the resultant executable program instruction set. Finally, what is needed is a Java application optimization method which permits a Java program, written to be portable, architecture independent, and secure, e.g., written in the Java language, to self configure itself for a particular hardware platform.
Based on the above and foregoing, it can be appreciated that there presently exists a need in the art for a method which mitigates the above-described deficiencies. The present invention was motivated by a desire to overcome the drawbacks and shortcomings of the presently available technology, and thereby fulfill this need in the art.
The present invention is directed to methods and corresponding software products for enhancing the efficiency of Java programs, especially as they pertain to the execution on multiple hardware platforms.
In one aspect, the present invention provides a method of creating a platform specific Java application from a cross platform Java application, which includes steps for declaring at least one of the variables associated with the cross platform Java application to be a constant, and purging unused functions and associated variables from the cross platform Java application to thereby produce the platform specific Java application. It will be appreciated that the at least one of the variables is declared constant in a first class while instructions for purging unused classes and associated variables are provided in a second class.
In another aspect, the present invention provides a method of creating a platform specific Java program from a cross platform Java program. Preferably, the method includes steps for defining a Constant class to declare selected variables associated with the cross platform Java program as constants, defining a Specialize class providing functions to specialize classes associated with the cross platform Java program with respect to the declared constants, evaluating the cross platform Java program in a Java run time environment using the declared constants, and modifying at least one of the classes associated with the cross platform Java program to thereby produce modified classes delimiting the platform specific Java program.
Preferably, the modifying step can encompass one or more of the following steps:
purging unused functions and associated variables from at least one of the classes associated with the cross platform Java program to thereby produce at least one first modified class;
replacing an existing function with a new function in at least one of the classes associated with the cross platform Java program to thereby produce at least one second modified class; and
inserting an additional function into at least one of the classes associated with the cross platform Java program to thereby produce at least one modified class.
In a different aspect, the present invention provides a method permitting creation and implementation of additional Java classes which interact to provide a desired, platform specific result. More specifically, the present invention provides a method of creating a platform specific Java program from a cross platform Java program. Preferably, the method includes steps for:
(a) defining a first Java class which provides the ability to declare constants;
(b) defining a second Java class which provides functions that specialize other classes with respect to the declared constants in the first Java class;
(c) using the first Java class to declare specific constants pertinent to desired platform support capabilities;
(d) using the second Java class to register specialization functions which provide the desired platform support capabilities;
(e) analyzing the execution of a Java application with respect to the constants in the first Java class; and
(f) based on the results of the analysis of the constants, performing resultant actions comprising at least one of ignoring, generating, and supplying appropriate desired code using the registered specialization functions specified by the second Java class.
In yet another aspect, the present invention provides a computer program product in a computer readable medium of instructions for creating a platform specific Java application from a cross platform Java application including instructions within the computer readable medium for declaring at least one of the variables associated with the cross platform Java application to be a constant, and instructions within the computer readable medium for purging unused functions and associated variables from the cross platform Java application to thereby produce the platform specific Java application.
According to a still further aspect, the present invention provides a computer program product in computer readable medium of instructions for creating a platform specific Java program from a cross platform Java program. Preferably, the instructions include first instructions within the computer readable medium for defining a Constant class to declare selected variables associated with the cross platform Java program as constants, second instructions within the computer readable medium for defining a Specialize class providing functions to specialize classes associated with the cross platform Java program with respect to the declared constants, third instructions within the computer readable medium for evaluating the cross platform Java program in the Java run time environment using the declared constants, and fourth instructions within the computer readable medium for modifying at least one of the classes associated with the cross platform Java program to instructions within the computer readable medium for thereby produce modified classes delimiting the platform specific Java program.